<?php

/**
 * @author Terry & 千里孤坟
 * @copyright 2009
 */

class DefAfterStatus {
	public function __construct(){
		$this->id = -1;
		$this->on = 0;		//开关
		$this->name = "基类";
		$this->time = 0;	//持续回合数，999即作为永久
		$this->n = 0;		//当前进行次数
	}

        public function checkex($a) {
                if(isset($this->excid) && in_array($a->cid,$this->excid)) {
                        $this->name = "<font color=blue>EX".$this->name."</font>";
                        $this->ex = 1;
                        $this->exskset();
                }   
        }

        public function exskset() {
                return 1;
        }  

	public function action($a,$b) {
		return 0;
	}

	public function cancel($a) {
		$a->defafter_status[$this->id]->on = 0;
		$a->defafter_status[$this->id]->n = 0;
	}
}

class Gnash extends DefAfterStatus {

	public function __construct(){
		$this->id = 1;
		$this->on = 0;		//开关
		$this->name = "食いしばり";
		$this->time = 0;	//持续回合数，999即作为永久
		$this->n = 0;		//当前进行次数
		$this->permanent = 1;	//持久效果
		$this->excid = array(145);
		$this->v = 1;
		$this->threshold = 0.1;
	}
	
	public function exskset() {
		$this->threshold = 0.15;
	}

	public function action($a,$b) {
		if($b->hp <= 0 && $b->before_status[17]->started != 1) {
			$this->checkex($b);
			$overhp = abs($b->hp);
			if($overhp <= $b->mxhp * $this->threshold) {
				$_SESSION['show'] .= $b->name.$this->name."发动，没有倒下。<br>";
				if($b->cid == 146) {
					$_SESSION['show'] .= $b->name."：“永不言败！”<br>";
				} elseif($b->cid == 51) {
					CalHelper::spec_talk($this,1,"最后的胜者是我！");
					CalHelper::cgdisplay('ww_2.jpg');
				} elseif($b->cid == 85) {
					CalHelper::spec_talk($this,2,'僕は、屑だ…');
					CalHelper::cgdisplay('cancer_4.jpg');
				}
				StatusHelper::cure_allspt($b);
				$b->hp = $this->v;
				//取消倒地
				if($b->before_status[0]->on == 1) {
					$b->before_status[0]->cancel($b);
					$b->defskill_status[0]->cancel($b);
				}
				$this->cancel($b);
				$b->eventskill_status[5]->on = 0;
				$b->eventskill_status[6]->on = 0;
			} else {
				$_SESSION['show'] .= $b->name."所受伤害过高，还是支撑不住倒下了...<br>";
			}
		}
	}
}

class UnlimitedCircle extends DefAfterStatus {

	public function __construct(){
		$this->id = 2;
		$this->on = 0;		//开关
		$this->name = "ウロボロスの環";
		$this->time = 0;	//持续回合数，999即作为永久
		$this->n = 0;		//当前进行次数
		$this->godds = 100;
		$this->permanent = 1;	//持久效果
	}

	public function action($a,$b) {
		if($b->hp <= 0 && $b->before_status[17]->started != 1) {
			$tmp = mt_rand(1,100);
			//$_SESSION['result'] .= $this->name."发动乱数：$tmp<br>";
			if($this->godds >= $tmp) {
				$_SESSION['show'] .= $b->name.$this->name."生效，发动特殊硬食！<br>";
				StatusHelper::cure_allspt($b);
				$b->hp = 100;
				//取消倒地
				if($b->before_status[0]->on == 1) {
					$b->before_status[0]->cancel($b);
					$b->defskill_status[0]->cancel($b);
				}
				$b->defafter_status[1]->cancel($b);
				$this->cancel($b);
			} else {
				$_SESSION['show'] .= $b->name.$this->name."未能发动。乱数：".$tmp."<br>";
			}
		}
	}
}

class RouseAfter extends DefAfterStatus {
	public function __construct(){
		$this->id = 3;
		$this->on = 0;		//开关
		$this->name = "觉醒";
		$this->time = 0;	//持续回合数，999即作为永久
		$this->n = 0;		//当前进行次数
		$this->permanent = 1;	//持久效果
	}

	public function action($a,$b) {
		if($b->hp <= 0) {
			if(CalHelper::ifgroupskill($b) == 20 && $b->groupskcount == 0) {
				$tmp = mt_rand(1,100);
				$_SESSION['result'] .= "神々の加護发动乱数：$tmp<br>";
				if(75 >= $tmp) {
					$_SESSION['show'] .= $b->name."发动神々の加護，残余的魂魄仍然留于体内...<br>";
					$b->groupskcount += 1;
					return 1;
				}
			}
			CalHelper::disillusion($b);
		}
	}
}

class Arise extends DefAfterStatus {

	public function __construct(){
		$this->id = 4;
		$this->on = 0;		//开关
		$this->name = "不屈の闘志";
		$this->time = 0;	//持续回合数，999即作为永久
		$this->n = 0;		//当前进行次数
		$this->permanent = 1;	//持久效果
		$this->v = 0.25;
		$this->excid = array(139,143);
	}

	public function exskset() {
		$this->v = 0.32;
	}

	public function action($a,$b) {
		if($b->hp <= 0 && $b->disillusion != 1 && $b->before_status[61]->on != 1) {
			$this->checkex($b);
			$_SESSION['show'] .= $b->name.$this->name."发动，从濒死中复活了。<br>";
			if($b->cid == 139) {
				CalHelper::spec_talk($this,1,$b->name."：这一切还没有结束，等待接受我重生后的愤怒吧！");
				CalHelper::cgdisplay('seahero_1.jpg');
			}	elseif($b->cid == 146) {
				$_SESSION['show'] .= $b->name."：“永不言败！”<br>";
			}
			StatusHelper::resetall($b);
			$b->hp = round($b->mxhp * $this->v);
			$this->cancel($b);
			$b->defafter_status[4]->on = 0;
			$b->eventskill_status[5]->on = 0;
			$b->eventskill_status[6]->on = 0;
			//倒地中
			$b->before_status[0]->on = 1;
			$b->defskill_status[0]->on = 1;
		}
	}

}

class DragonReverseScale extends DefAfterStatus {
	public function __construct(){
		$this->id = 5;
		$this->on = 0;		//开关
		$this->name = "竜神の逆鱗";
		$this->time = 0;	//持续回合数，999即作为永久
		$this->n = 0;		//当前进行次数
		$this->godds = 30;
		$this->permanent = 1;	//持久效果
	}

	public function action($a,$b) {
		if($b->hp > floor($b->mxhp * 0.35)) {
			return 0;
		}
		
		if($b->hited) {
			$tmp = mt_rand(1,100);
			if($this->godds >= $tmp){
				if(mt_rand(1,2) == 1) {
					$_SESSION['show'] .= $b->name.$this->name."发动，进入蓄力状态。乱数".$tmp."<br>";
					StatusHelper::phydmgdouble($b);
				} else {
					$_SESSION['show'] .= $b->name.$this->name."发动，进入集中状态。乱数".$tmp."<br>";
					StatusHelper::mgrdmgdouble($b);
				}
			} else {
				$_SESSION['show'] .= $b->name.$this->name."未能发动，乱数".$tmp."<br>";
			}
		}
	}

}

class SDayDefafter extends DefAfterStatus {

	public function __construct(){
		$this->id = 8;
		$this->on = 0;		//开关
		$this->name = "通天巨塔";
		$this->time = 0;	//持续回合数，999即作为永久
		$this->n = 0;		//当前进行次数
	}

	public function action($a,$b) {
		if($_SESSION['T'] == 15) {
			if($b->hp <= 0 && $b->bombed != 1 && $b->towered != 1) {
				$_SESSION['result'] .= "巴比伦的奇迹，促使你再一次站起来...<br>";
				$_SESSION['show'] .= $b->name."濒死的身体内注入了一股远方的力量，没有倒下<br>";
				StatusHelper::cure_allspt($b);
				$b->hp = 100;
				//取消倒地
				if($b->before_status[0]->on == 1) {
					$b->before_status[0]->cancel($b);
					$b->defskill_status[0]->cancel($b);
				}
				$b->towered = 1;
			}
		}
	}

	public function cancel($a) {
		return 0;
	}
}

class DropChest extends DefAfterStatus {

	public function __construct(){
		$this->id = 9;
		$this->on = 0;		//开关
		$this->name = "宝箱掉落";
		$this->time = 0;	//持续回合数，999即作为永久
		$this->n = 0;		//当前进行次数
	}

	public function action($a,$b) {
		if(isset($b->hp) && $b->hp <= 0) {
			$baseluk = ($a->luk > 50) ? $a->luk : 50;
			$cuchest = 2000 + ($baseluk - 50) * 5;
			$agchest = 700 + ($baseluk - 50) * 5;
			$auchest = 270 + ($baseluk - 50) * 5;
			$ptchest = 30 + ($baseluk - 50) * 5;
			$nochest = 10000 - ($cuchest + $agchest + $auchest + $ptchest);
			if($nochest < 0) {
				$nochest = 0;
			}
			$tmp = mt_rand(1,10000);
#			$_SESSION['result'] .= "宝箱乱数".$tmp."<br>无：".$nochest."<br>铜：".$cuchest."<br>银：".$agchest."<br>金：".$auchest."<br>白金：".$ptchest."<br>";
			if($tmp <= $nochest) {
				$_SESSION['show'] .= "<strong>".$b->name."没有掉落宝箱...</strong><br>";
			} elseif($tmp > $nochest && $tmp <= ($nochest + $cuchest)) {
				$_SESSION['show'] .= "<strong><font color=#FF8000>".$b->name."掉落了铜宝箱！</font></strong><br>";
			} elseif($tmp > ($nochest + $cuchest) && $tmp <= ($nochest + $cuchest + $agchest)) {
				$_SESSION['show'] .= "<strong><font color=#808080>".$b->name."掉落了银宝箱！</font></strong><br>";
			} elseif($tmp > ($nochest + $cuchest + $agchest) && $tmp <= ($nochest + $cuchest + $agchest + $auchest)) {
				$_SESSION['show'] .= "<strong><font color=#B8860B>".$b->name."掉落了金宝箱！</font></strong><br>";
			} else {
				$_SESSION['show'] .= "<strong><font color=#B3ADE4>".$b->name."掉落了白金宝箱！</font></strong><br>";
			}
		}
	}

	public function cancel($a) {
		return 0;
	}
}

?>
